using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace EasyProjects.TimeLogger
{
    public partial class SplashForm : Form
    {
        private bool isNeedClose = false;

        /// <summary>
        /// Used for detecting display method. Is it splash or about window.
        /// </summary>
        public bool IsNeedClose
        {
            get { return isNeedClose; }
            set
            {
                isNeedClose = value;
                if (isNeedClose)
                    progressBar1.Visible = false;
            }
        }

        public SplashForm()
        {
            InitializeComponent();
        }

        private void SplashForm_Load(object sender, EventArgs e)
        {

            if (!isNeedClose)//if splash start new thread
            {
                Thread launchThread = new Thread(new ThreadStart(processApplicationDownload));
                launchThread.SetApartmentState(ApartmentState.STA);
                launchThread.Start();
            }
        }

        private static void processApplicationDownload()
        {

            //launch application in other thread
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
            Application.Run(new MainForm());
        }

        private void SplashForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = !isNeedClose; //close form if it is about screen
        }

        private void SplashForm_MouseClick(object sender, MouseEventArgs e)
        {
            Close();
        }
    }
}